<?php
/**
 * @Author: WHK
 * @Date:   2014-10-28 15:00:57
 * @Last Modified by:   WHK
 * @Last Modified time: 2014-10-29 17:40:48
 */

class CustomControl extends CommonControl
{
	
	public function index(){
		$cusdb = K('Custom')->get_all();
		$this->assign('cusdb',$cusdb);
		$this->display();
	}
	public function cus_edit(){
		if(IS_POST){
			if($_POST['custom_sex']){
				$sex = '女';
			}else{
				$sex = '男';
			}
			if(isset($_POST['note'])){
				$_POST['note'];
			}else{
				$_POST['note']="";
			}
			$customdb = array(
				'custom_name'=>$_POST['custom_name'],
				'serve_type'=>$_POST['serve_type'],
				'custom_email'=>$_POST['custom_email'],
				'custom_sex'=>$sex,
				'serve_year'=>$_POST['serve_year'],
				'satartime'=>$_POST['satartime'],
				'endtime'=>$_POST['endtime'],
				'note'=>$_POST['note']

				);

			$result = K('Custom')->edit($_POST['id'],$customdb);
			if($result){
				$this->success('修改成功','Custom/index');

			}else{
				$this->error('修改失败');
			}
		}
		$cusdb = K('Custom')->get_one(array('id'=>Q('get.id'))); 
		$this->assign('cusdb',$cusdb);


		$this->display('edit.html');
	}
	public function add_custom(){
	if(IS_POST){
			if($_POST['custom_sex']){
				$sex = '女';
			}else{
				$sex = '男';
			}
			$customdb = array(
				'custom_name'=>$_POST['custom_name'],
				'serve_type'=>$_POST['serve_type'],
				'custom_email'=>$_POST['custom_email'],
				'custom_sex'=>$sex,
				'serve_year'=>$_POST['serve_year'],
				'satartime'=>$_POST['satartime'],
				'endtime'=>$_POST['endtime'],
				'note'=>$_POST['note']

				);
			$result = K('Custom')->add_($customdb);
			if($result){
				$this->success('添加成功');

			}else{
				$this->error('添加失败');
			}
		}
		$this->display('add_custom.html');
	}
	/**
	 * [reg 购买成功给客户发信息邮件]
	 * @return [type] [description]
	 */
	public function reg(){

		//客户信息
		$cusdb = K('Custom')->get_one(array('id'=>Q('get.id'))); 
		if($cusdb['custom_sex']=="男"){
			$sex = "先生";
		}else{
			$sex="小姐";
		}
		// $msg = file_get_contents(ROOT_PATH ."mailmsg/reg-msg.html");  定界符模板页面地址
				$msg2=<<<msg
	<div style="background: #2B2A2A;width: 980px;margin: 0 auto;height: 65px;">
			<ul style="width: 980px;overflow: hidden;">
					<li style="float:left;line-height: 65px;list-style: none;" ><img style="width:77px;height:44px;" src="http://www.cooldreamer.com/Template/uimaker.com/Img/logo-samll.png" alt="" /></li>
					<li style="float:left;line-height: 65px;list-style: none;" ><a style="color: #fff;padding-left: 20px;text-decoration: none;font-size: 13px;" href="www.cooldreamer.com">首页</a></li>
					<li style="float:left;line-height: 65px;list-style: none;" ><a style="color: #fff;padding-left: 20px;text-decoration: none;font-size: 13px;" href="http://www.cooldreamer.com/Index/Cms/index.html">CMS</a></li>
					<li style="float:left;line-height: 65px;list-style: none;" ><a style="color: #fff;padding-left: 20px;text-decoration: none;font-size: 13px;" href="http://www.cooldreamer.com/Index/Apply/index.html">申请页面</a></li>
					<li style="float:left;line-height: 65px;list-style: none;" ><a style="color: #fff;padding-left: 20px;text-decoration: none;font-size: 13px;" href="http://www.cooldreamer.com/Index/Bigview/index.html">大事件</a></li>
					<li style="float:left;line-height: 65px;list-style: none;" ><a style="color: #fff;padding-left: 20px;text-decoration: none;font-size: 13px;" href="http://www.cooldreamer.com/show/bbs">BBS</a></li>
				</ul>
	</div>
	<div style="width: 978px;border:1px #EDECEC solid; border-top: none;margin: 0 auto;overflow: hidden;">
		<p style="font-size: 14px;color: #333333;text-indent: 5px;padding:20px;">尊敬的客户 <a href="" class="name">{$cusdb['custom_name']}</a>{$sex}:</p>
		<p style="font-size: 12px;color: #2B2A2A;width: 980px;font-size: 12px;margin: 0 auto;word-break:break-all; /*支持IE，chrome，FF不支持*/

　　word-wrap:break-word;/*支持IE，chrome，FF*/line-height: 2;text-indent: 10px;">
				您购买的{$cusdb['serve_type']}服务于{$cusdb['satartime']}--{$cusdb['endtime']}共{$cusdb['serve_year']}年,如果您有任何问题，欢迎邮至852777213@qq.com,或者502443279@qq.com.我们会在每一时间联系您的。
 		</p>
 		<p style="font-size: 13px; color: #2B2A2A;line-height:5;padding-top:20px;">酷梦者工作室(CMD)</p>
 		<hr / style="border:1px dotted #dddddd;">
	<div style="background:#F4F4F4;"><img src="http://www.cooldreamer.com/Template/uimaker.com/Img/mailweixin.png" alt="" /></div>	
	</div>
msg;
		$state = Mail::send(
		     "{$cusdb['custom_email']}",
		     " 酷梦者(CMD) ",
		      "酷梦者(CMD)购买成功通知",
		      "{$msg2}"  
 		 ); 
 	
		//如果发送成功
 		  if($state){
				$this->success('成功发送','');
	 		  
	 		}else{
	 			$this->success('数据连接错误','');
	 		}
	}
	/**
	 * [pay_waring 续费通知邮件]
	 * @return [type] [description]
	 */
	public function pay_waring(){
	}
	public function del_cus(){
		$resutl =K('Custom')->del_($_GET['id']);
		if($resutl){
			$this->success('删除成功');
		}else{
			$this->error('删除失败');
		}
		
	}
}
	